//
//  XS_VIPLogItemCell.swift
//  XueDao
//
//  Created by Mac on 2021/2/2.
//

import UIKit

class XS_VIPLogItemCell: UICollectionViewCell {

    @IBOutlet weak var backView: UIView!
    @IBOutlet weak var statusBtn: QMUIButton!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var expireTimeLabel: UILabel!
    @IBOutlet weak var priceLabel: UILabel!
    @IBOutlet weak var finalPriceLabel: UILabel!
    
    @IBOutlet weak var cancelBtn: UIButton!
    @IBOutlet weak var buyBtn: UIButton!
    
    var _model : XS_VIPLogItemModel!
    public var model : XS_VIPLogItemModel!{
        set{
            _model = newValue
            //设置数据
            statusBtn.isSelected = newValue.payResult == "payment"
            
            cancelBtn.isHidden = newValue.payResult != "nopay"
            buyBtn.isHidden = newValue.payResult != "nopay"
            
            timeLabel.text = newValue.createTime
            titleLabel.text = newValue.title
            expireTimeLabel.text = newValue.expirationTime ?? ""
            priceLabel.isHidden = newValue.payResult == "payment"
            finalPriceLabel.isHidden = newValue.payResult != "payment"
            let finalPriceStr = "实付￥"+"\(newValue.payPrice)"
            let attr = NSMutableAttributedString.init(string: finalPriceStr)
            attr.addAttribute(.foregroundColor, value: UIColor.qmui_color(withHexString: "#FF0000")!, range: NSRange.init(location: 0, length: finalPriceStr.count))
            finalPriceLabel.attributedText = attr
        }
        get{
            return _model
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        cancelBtn.layer.borderWidth = 1
        cancelBtn.layer.borderColor = UIColor.qmui_color(withHexString: "#AAB1B7")?.cgColor
        statusBtn.imagePosition = .left
        statusBtn.spacingBetweenImageAndTitle = 4
        
        // Shadow Code
        backView.layer.shadowColor = UIColor.init(red: 205.0/255.0, green: 205.0/255.0, blue: 205.0/255.0, alpha: 0.5).cgColor;
        backView.layer.shadowOffset = CGSize.init(width: 0, height: 1);
        backView.layer.shadowRadius = 4;
        backView.layer.shadowOpacity = 1;
    }
    
    @IBAction func cancelBtnAction(_ sender: UIButton) {
        
    }
    
    @IBAction func buyBtnAction(_ sender: UIButton) {
        
    }
    
}
